package com.utn.tp.integrador.activities;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.utn.tp.integrador.R;
import com.utn.tp.integrador.controlador.ControladorAccionesSingleton;

public class MandarEmail extends Activity {
	private String email;
	private Bundle extras;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mandar_email);

		final EditText asunto = (EditText) findViewById(R.id.asunto);
		final EditText cuerpo = (EditText) findViewById(R.id.cuerpoMail);
		final Button enviar = (Button) findViewById(R.id.btn_enviar);

		extras = getIntent().getExtras();
		if (extras != null) {
			email = extras.getString("email");
		}

		enviar.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				ControladorAccionesSingleton
						.getInstance(MandarEmail.this)
						.getControlador()
						.mandarMail(email, asunto.getText().toString(),
								cuerpo.getText().toString(), getDatePhone(),
								getHourPhone(), extras.getString("nombre"), 2);
			}
		});

		setTitle("Mandar E-mail");
	}

	private String getDatePhone() {
		Calendar cal = new GregorianCalendar();
		Date date = cal.getTime();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		String formattedDate = df.format(date);
		return formattedDate;
	}

	public static String getHourPhone() {
		Date dt = new Date();
		SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
		String formattedHour = df.format(dt.getTime());
		return formattedHour;
	}
}
